﻿using SalesPages.Infrastructure.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using SalesPages.Infrastructure;
using StackExchange.Redis;

namespace SalesPages.Manager
{
    public class CacheManager : ICacheManager
    {
        private IRedisCacheService redisCacheService;

        public CacheManager(IRedisCacheService redisCacheService)
        {
            this.redisCacheService = redisCacheService;
        }
        public IDictionaryEnumerator GetAll()
        {
            throw new NotImplementedException();
        }

        public object GetCacheByKey(string key)
        {
            return redisCacheService.StringGet<object>(key);
        }

        public T GetCacheByKey<T>(string key) where T : class
        {
            return redisCacheService.StringGet<T>(key);
        }

        public void Remove(string key)
        {
             redisCacheService.KeyRemove(key);
        }

        public void SetCache(string key, object value, int min)
        {
            redisCacheService.StringSet(key, value, new TimeSpan(DateTime.Now.AddMinutes(min).Ticks));
        }

        public void SetCacheParallel(IList<Tuple<string, object>> caches, int min)
        {
            redisCacheService.StringSetBatch(caches, new TimeSpan(DateTime.Now.AddMinutes(min).Ticks));
        }
    }
}
